package com.longxi.tianjintianbao.ui.activity.login;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.longxi.tianjintianbao.AppConst;
import com.longxi.tianjintianbao.MyApplication;
import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.model.PropertyCompany;
import com.longxi.tianjintianbao.ui.activity.assetscheck.AssetsWebServiceActivity;
import com.longxi.tianjintianbao.ui.activity.main.MainActivity;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.presenter.login.LoginAtPresenter;
import com.longxi.tianjintianbao.ui.view.login.ILoginAtView;
import com.longxi.tianjintianbao.utils.LogUtils;
import com.longxi.tianjintianbao.utils.MyUtils;

import butterknife.BindView;
import cn.jpush.android.api.JPushInterface;

public class LoginActivity extends BaseActivity<ILoginAtView, LoginAtPresenter> implements ILoginAtView {

    @BindView(R.id.tvChangeIp)
    TextView mTvChangeIp;
    @BindView(R.id.etUsername)
    EditText mEtUsername;
    @BindView(R.id.etPassword)
    EditText mEtPassword;
    @BindView(R.id.tvRememberPwd)
    TextView mTvRememberPwd;
    @BindView(R.id.btnLogin)
    Button mBtnLogin;
    @BindView(R.id.tvChangeAccount)
    TextView mTvChangeAccount;

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_login;
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter.autoLogon();
//        mPresenter.offlineMode();
    }

    @Override
    public void initListener() {
        super.initListener();
        mBtnLogin.setOnClickListener(v -> mPresenter.login());
        if(PropertyCompany.getData2().size() == 1){//判断是不是只有一个物业公司 是的话直接隐藏按钮
            mTvChangeIp.setVisibility(View.GONE);
        }
        mTvChangeIp.setOnClickListener(v -> mPresenter.getIP());
//        mTvChangeAccount.setOnClickListener(v -> mPresenter.toChangeAccountActivity());
        mTvChangeAccount.setOnClickListener(v -> jumpToActivity(AssetsWebServiceActivity.class));
        mTvRememberPwd.setOnClickListener(v -> mPresenter.rememberPwd());
    }

    @Override
    protected LoginAtPresenter createPresenter() {
        return new LoginAtPresenter(this);
    }

    @Override
    public TextView getTvChangeIp() {
        return mTvChangeIp;
    }

    @Override
    public EditText getEtUsername() {
        return mEtUsername;
    }

    @Override
    public EditText getEtPassword() {
        return mEtPassword;
    }

    @Override
    public Button getBtnLogin() {
        return mBtnLogin;
    }

    @Override
    public TextView getTvRememberPwd() {
        return mTvRememberPwd;
    }

    @Override
    public TextView getTvChangeAccount() {
        return mTvChangeAccount;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mPresenter.onActivityResult(requestCode, resultCode, data);
    }
}
